﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Data;
using System.Collections;

namespace Librerias
{
    [Serializable]
    public abstract class ENBase
    {
        #region Constantes

        public const int kIdNoValido = -1;
        public const decimal kDecimalInicial = 0.00M;

        #endregion

        #region Variables privadas

        [NonSerialized]
        private static string cadenaConexion;

        #endregion

        #region Propiedades públicas

        public static string CadenaConexion
        {
            get { return cadenaConexion; }
            set { cadenaConexion = value; }
        }

        #endregion

        #region Constructores

        /// <summary>
        /// Constructor vacío
        /// </summary>
        public ENBase()
        {

        }

        #endregion

        #region Constructor estático

        /// <summary>
        /// Constructor estático
        /// </summary>
        /*      static ENBase()
              {
                  cadenaConexion = "Data Source=ANGEL1\\SQLEXPRESS;Initial Catalog=Ateneo;Persist Security Info=True;";// string.Empty;

              }*/

        #endregion

        #region Métodos públicos estáticos
        /// <summary>
        /// Valida DNI
        /// </summary>
        /// <param name="d">dni</param>
        /// <returns>Si V</returns>
        public bool ValidarDni(string d)
        {
            bool correcto = false; ;
            string patron = @"^\d{8}[a-zA-Z]{1}";
            if (Regex.Match(d, patron).Success)
                correcto = true;
            return correcto;
        }

        /// <summary>
        /// Valida ISBN
        /// </summary>
        /// <param name="d">isbn</param>
        /// <returns>Si V</returns>
        public bool ValidarIsbn(string d)
        {
            bool correcto = false; ;
            string patron = @"^\d{13}";
            if (Regex.Match(d, patron).Success)
                correcto = true;
            return correcto;
        }

        /// <summary>
        /// Valida URL
        /// </summary>
        /// <param name="em">url</param>
        /// <returns>Si V</returns>
        public bool ValidarUrl(string em)
        {
            bool correcto = false;
            // string patron = @"^[a-zA-Z0-9_-]{2,}[@][a-zA-Z0-9_-]{2,}[.]{1}[a-zA-Z]{2,4}";
            string patron = @"(http://|https://|)([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";
            if (Regex.Match(em, patron).Success)
                correcto = true;
            return correcto;
        }

        /// <summary>
        /// Valida Strings
        /// </summary>
        /// <param name="n">string</param>
        /// <returns>Si v</returns>
        public bool ValidarStrings(string n)
        {
            bool correcto = false;
            string patron = @"^[a-zA-ZñÑ]";
            if (Regex.Match(n, patron).Success)
                correcto = true;
            return correcto;

        }

        /// <summary>
        /// Valida CP
        /// </summary>
        /// <param name="cp">CP</param>
        /// <returns>Si V</returns>
        public bool ValidarCP(string cp)
        {
            bool correcto = false;
            string patron = @"^\d{5}";
            if (Regex.Match(cp, patron).Success)
                correcto = true;
            return correcto;
        }

        /// <summary>
        /// Validsa Teléfono
        /// </summary>
        /// <param name="tel">teléfono</param>
        /// <returns>Si V</returns>
        public bool ValidarTelefono(string tel)
        {
            bool correcto = false;
            string patron = @"^9\d{8}";
            string patron2 = @"^6\d{8}";
            if (Regex.Match(tel, patron).Success || Regex.Match(tel, patron2).Success)
                correcto = true;
            return correcto;
        }

        /// <summary>
        /// Valida email
        /// </summary>
        /// <param name="em">email</param>
        /// <returns>Si V</returns>
        public bool ValidarEmail(string em)
        {
            bool correcto = false;
           // string patron = @"^[a-zA-Z0-9_-]{2,}[@][a-zA-Z0-9_-]{2,}[.]{1}[a-zA-Z]{2,4}";
            string patron = @"^[a-zA-Z0-9-._-]{2,}[@][a-zA-Z0-9_-]{2,}[.]{1}[a-zA-Z]{2,4}";
            if (Regex.Match(em, patron).Success)
                correcto = true;
            return correcto;
        }

        /// <summary>
        /// Valida Clave
        /// </summary>
        /// <param name="cla">Clave</param>
        /// <returns>Si V</returns>
        public bool ValidarClave(string cla)
        {
            bool correcto = false;
            string patron = @"[0-9a-zA-Z]+";
            if (Regex.Match(cla, patron).Success)
                correcto = true;
            return correcto;
        }

        /// <summary>
        /// Valida nº
        /// </summary>
        /// <param name="dec">numero</param>
        /// <returns>Si V</returns>
        public bool ValidarNumeros(string dec)
        {
            bool correcto = false;
            string patron = @"[0-9]$";
            if (Regex.Match(dec, patron).Success)
                correcto = true;
            return correcto;
        }

        /// <summary>
        /// Valida Decimal
        /// </summary>
        /// <param name="dec">decimal</param>
        /// <returns>si v</returns>
        public bool ValidarDecimal(string dec)
        {
            bool correcto = false;
            string patron = @"^[0-9]{1,5}(\.[0-9]{0,2})?$";
            if (Regex.Match(dec, patron).Success)
                correcto = true;
            return correcto;
        }


        /// <summary>
        /// Valida creditos
        /// </summary>
        /// <param name="cred">creditos</param>
        /// <returns>Si V</returns>
        public bool ValidarCreditos(string cred)
        {
            bool correcto = false;
            string patron = @"^[0-9]{1,2}(\.[05])?$";
            if (Regex.Match(cred, patron).Success)
                correcto = true;
            return correcto;
        }
        #endregion
    }
}